package com.demostic.demostic_test.ui;

import android.content.Context;
import android.graphics.Canvas;
import android.graphics.Color;
import android.graphics.Paint;
import android.graphics.RectF;
import android.graphics.Typeface;
import android.util.AttributeSet;
import android.util.Log;
import android.view.View;

public class RoundProgressBar extends View {
    public static final int FILL = 1;
    public static final int FILL_UP = 2;
    public static final int STROKE = 0;
    private int max;
    private Paint paint;
    private int progress;
    private int roundColor;
    private int roundProgressColor;
    private float roundWidth;
    private int style;
    private int textColor;
    private boolean textIsDisplayable;
    private float textSize;

    public RoundProgressBar(Context context) {
        this(context, null);
    }

    public RoundProgressBar(Context context, AttributeSet attrs) {
        this(context, attrs, 0);
    }

    public RoundProgressBar(Context context, AttributeSet attrs, int defStyle) {
        super(context, attrs, defStyle);
        init();
    }

    private void init() {
        this.paint = new Paint();
        this.roundColor = -148972;
        this.roundProgressColor = -226547;
        this.textColor = -16711936;
        this.textSize = 15.0f;
        this.roundWidth = 5.0f;
        this.max = 100;
        this.textIsDisplayable = true;
        this.style = 0;
    }

    /* access modifiers changed from: protected */
    @Override // android.view.View
    public void onDraw(Canvas canvas) {
        int angle;
        super.onDraw(canvas);
        int centre = getWidth() / 2;
        int radius = (int) (((float) centre) - (this.roundWidth / 2.0f));
        this.paint.setColor(Color.parseColor("#dcdcdc"));
        if (this.style == 2) {
            this.paint.setStyle(Paint.Style.FILL_AND_STROKE);
        } else {
            this.paint.setStyle(Paint.Style.STROKE);
        }
        this.paint.setStrokeWidth(this.roundWidth);
        this.paint.setAntiAlias(true);
        canvas.drawCircle((float) centre, (float) centre, (float) radius, this.paint);
        Log.e("log", centre + "");
        this.paint.setStrokeWidth(this.roundWidth);
        this.paint.setColor(Color.parseColor("#00bdb5"));
        RectF oval = new RectF((float) (centre - radius), (float) (centre - radius), (float) (centre + radius), (float) (centre + radius));
        switch (this.style) {
            case 0:
                this.paint.setStyle(Paint.Style.STROKE);
                canvas.drawArc(oval, 0.0f, (float) ((this.progress * 360) / this.max), false, this.paint);
                break;
            case 1:
                this.paint.setStyle(Paint.Style.FILL_AND_STROKE);
                if (this.progress != 0) {
                    canvas.drawArc(oval, 0.0f, (float) ((this.progress * 360) / this.max), true, this.paint);
                    break;
                }
                break;
            case 2:
                this.paint.setStyle(Paint.Style.FILL_AND_STROKE);
                if (this.progress != 0) {
                    int angle2 = (this.progress * 360) / this.max;
                    if (angle2 / 2 < 90) {
                        angle = Math.abs(90 - (angle2 / 2));
                    } else {
                        angle = 360 - Math.abs(90 - (angle2 / 2));
                    }
                    canvas.drawArc(oval, (float) angle, (float) ((this.progress * 360) / this.max), false, this.paint);
                    break;
                }
                break;
        }
        this.paint.setStrokeWidth(0.0f);
        this.paint.setColor(Color.parseColor("#00bdb5"));
        this.paint.setTextSize(40.0f);
        this.paint.setTypeface(Typeface.DEFAULT_BOLD);
        int percent = (int) ((((float) this.progress) / ((float) this.max)) * 100.0f);
        float textWidth = this.paint.measureText(percent + "%");
        if (this.textIsDisplayable && percent != 0) {
            canvas.drawText(percent + "%", ((float) centre) - (textWidth / 2.0f), ((float) centre) + (this.textSize / 2.0f), this.paint);
        }
    }

    public synchronized int getMax() {
        return this.max;
    }

    public synchronized void setMax(int max2) {
        if (max2 < 0) {
            throw new IllegalArgumentException("max not less than 0");
        }
        this.max = max2;
    }

    public synchronized int getProgress() {
        return this.progress;
    }

    public synchronized void setProgress(int progress2) {
        if (progress2 < 0) {
            throw new IllegalArgumentException("progress not less than 0");
        }
        if (progress2 > this.max) {
            progress2 = this.max;
        }
        if (progress2 <= this.max) {
            this.progress = progress2;
            postInvalidate();
        }
    }

    public int getCircleColor() {
        return this.roundColor;
    }

    public void setCircleColor(int circleColor) {
        this.roundColor = circleColor;
    }

    public int getCircleProgressColor() {
        return this.roundProgressColor;
    }

    public void setCircleProgressColor(int circleProgressColor) {
        this.roundProgressColor = circleProgressColor;
    }

    public int getTextColor() {
        return this.textColor;
    }

    public void setTextColor(int textColor2) {
        this.textColor = textColor2;
    }

    public float getTextSize() {
        return this.textSize;
    }

    public void setTextSize(float textSize2) {
        this.textSize = textSize2;
    }

    public float getRoundWidth() {
        return this.roundWidth;
    }

    public void setRoundWidth(float roundWidth2) {
        this.roundWidth = roundWidth2;
    }

    public void setTextIsDisplayable(boolean flag) {
        this.textIsDisplayable = flag;
    }

    public void setStyle(int style2) {
        this.style = style2;
    }
}
